package com.ruoyi.ylyx.controller;

import java.util.List;

import com.ruoyi.system.service.ISysPostService;
import com.ruoyi.ylyx.domain.YlyxRecuittype;
import com.ruoyi.ylyx.service.IYlyxRecuittypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ylyx.domain.YlyxRecruitpost;
import com.ruoyi.ylyx.service.IYlyxRecruitpostService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 招聘岗位Controller
 * 
 * @author yuexl
 * @date 2021-02-05
 */
@Controller
@RequestMapping("/ylyx/recruitpost")
public class YlyxRecruitpostController extends BaseController
{
    private String prefix = "ylyx/recruitpost";

    @Autowired
    private IYlyxRecruitpostService ylyxRecruitpostService;
    @Autowired
    private IYlyxRecuittypeService ylyxRecuittypeService;
    @Autowired
    private ISysPostService postService;

    @RequiresPermissions("ylyx:recruitpost:view")
    @GetMapping()
    public String recruitpost(ModelMap mmap)
    {
        mmap.put("types", ylyxRecuittypeService.selectYlyxRecuittypeList(new YlyxRecuittype()));
        return prefix + "/recruitpost";
    }

    /**
     * 查询招聘岗位列表
     */
    @RequiresPermissions("ylyx:recruitpost:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YlyxRecruitpost ylyxRecruitpost)
    {
        startPage();
        List<YlyxRecruitpost> list = ylyxRecruitpostService.selectYlyxRecruitpostList(ylyxRecruitpost);
        return getDataTable(list);
    }

    /**
     * 导出招聘岗位列表
     */
    @RequiresPermissions("ylyx:recruitpost:export")
    @Log(title = "招聘岗位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YlyxRecruitpost ylyxRecruitpost)
    {
        List<YlyxRecruitpost> list = ylyxRecruitpostService.selectYlyxRecruitpostList(ylyxRecruitpost);
        ExcelUtil<YlyxRecruitpost> util = new ExcelUtil<YlyxRecruitpost>(YlyxRecruitpost.class);
        return util.exportExcel(list, "recruitpost");
    }

    /**
     * 新增招聘岗位
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("posts", postService.selectPostAll());
        mmap.put("types", ylyxRecuittypeService.selectYlyxRecuittypeList(new YlyxRecuittype()));
        return prefix + "/add";
    }

    /**
     * 新增保存招聘岗位
     */
    @RequiresPermissions("ylyx:recruitpost:add")
    @Log(title = "招聘岗位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YlyxRecruitpost ylyxRecruitpost)
    {
        return toAjax(ylyxRecruitpostService.insertYlyxRecruitpost(ylyxRecruitpost));
    }

    /**
     * 修改招聘岗位
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        YlyxRecruitpost ylyxRecruitpost = ylyxRecruitpostService.selectYlyxRecruitpostById(id);
        mmap.put("ylyxRecruitpost", ylyxRecruitpost);
        mmap.put("posts", postService.selectPostAll());
        mmap.put("types", ylyxRecuittypeService.selectTypeByRecruitId(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存招聘岗位
     */
    @RequiresPermissions("ylyx:recruitpost:edit")
    @Log(title = "招聘岗位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YlyxRecruitpost ylyxRecruitpost)
    {
        return toAjax(ylyxRecruitpostService.updateYlyxRecruitpost(ylyxRecruitpost));
    }

    /**
     * 删除招聘岗位
     */
    @RequiresPermissions("ylyx:recruitpost:remove")
    @Log(title = "招聘岗位", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ylyxRecruitpostService.deleteYlyxRecruitpostByIds(ids));
    }
}
